package com.quik.web.room.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.quik.entity.Room;
import com.quik.entity.RoomArea;
import com.quik.entity.RoomType;
import com.quik.entity.RoomTypeBoundProduct;
import com.quik.web.room.mapper.RoomDao;

/**
 * 功能说明：
 *        接口RoomService实现类
 * @author Jenny
 *
 */
@Service
public class RoomServiceImpl implements RoomService {
	
	@Autowired
	private RoomDao dao;
	
	/**
	 * 根据条件查询房间类型总数
	 * @return
	 */
	@Override
	public int findRoomTypeCount(String roomTypeName, String productNo, String productName) throws Exception{
		int count = dao.findRoomTypeCount(roomTypeName, productNo, productName);
		return count;
	}
	
	/**
	 * 根据条件查询房间类型列表（分页）
	 * @param roomType
	 * @param productNo
	 * @param productName
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findRoomType(String roomTypeName, String productNo, String productName, 
		Integer intPage, Integer pageSize) throws Exception{
		List list = dao.findRoomType(roomTypeName, productNo, productName, intPage, pageSize);
		return list;
	}
	
	/**
	 * 检查用户是否有重名
	 * @param roomTypeName
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean checkRoomTypeName(String roomTypeName) throws Exception{
		int count = dao.findRoomTypeCountByName(roomTypeName);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增房间类型
	 * @param roomType
	 * @throws Exception
	 */
	public void addRoomType(RoomType roomType) throws Exception{
		RoomTypeBoundProduct boundProduct = null;
		
		if(roomType.getProductNo() != null && roomType.getProductNo().length() > 0){
			boundProduct = new RoomTypeBoundProduct();
			boundProduct.setCrt_date(roomType.getCrt_date());
			boundProduct.setCrt_user(roomType.getCrt_user());
			boundProduct.setProduct_no(roomType.getProductNo());
		}
		
		dao.addRoomType(roomType, boundProduct);
	}
	
	/**
	 * 根据条件查询房间区域总数
	 * @param roomAreaName
	 * @return
	 * @throws Exception
	 */
	@Override
	public int findRoomAreaCount(String roomAreaName) throws Exception{
		int count = dao.findRoomAreaCount(roomAreaName);
		return count;
	}
	
	/**
	 * 根据条件查询房间区域列表（分页）
	 * @param roomAreaName
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findRoomArea(String roomAreaName, int intPage, int pageSize) throws Exception{
		List list = dao.findRoomArea(roomAreaName, intPage, pageSize);
		return list;
	}
	
	/**
	 * 检查房间区域是否同名
	 * @param roomAreaName
	 * @return 如果同名返回true, 否则返回False
	 * @throws Exception
	 */
	@Override
	public boolean checkRoomAreaName(String roomAreaName) throws Exception{
		int count = dao.findRoomAreaCountByRoomAreaName(roomAreaName);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增房间区域
	 * @param roomArea
	 * @throws Exception
	 */
	@Override
	public void addRoomArea(RoomArea roomArea) throws Exception{
		dao.addRoomArea(roomArea);
	}
	
	/**
	 * 根据条件查询房间总数
	 * @param roomNo
	 * @param roomTypeName
	 * @param roomAreaName
	 * @return
	 * @throws Exception
	 */
	@Override
	public int findRoomCount(String roomNo, String roomTypeName, String roomAreaName) throws Exception{
		int count = dao.findRoomCount(roomNo, roomTypeName, roomAreaName);
		return count;
	}
	
	/**
	 * 根据条件查询房间列表（分页）
	 * @param roomNo
	 * @param roomTypeName
	 * @param roomAreaName
	 * @param intPage
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findRoom(String roomNo, String roomTypeName, String roomAreaName, int intPage, int pageSize)throws Exception{
		List list = dao.findRoom(roomNo, roomTypeName, roomAreaName, intPage, pageSize);
		return list;
	}
	
	/**
	 * 检查房间编号是否重复
	 * @param roomNo
	 * @return 如果重复返回true, 否则返回false
	 * @throws Exception
	 */
	@Override
	public boolean checkRoomNo(String roomNo) throws Exception{
		int count = dao.findRoomCountByRoomNo(roomNo);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增房间
	 * @param room
	 * @throws Exception
	 */
	@Override
	public void addRoom(Room room) throws Exception{
		dao.addRoom(room);
	}
}
